<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    {include file='public/_meta' /}
    <script src="__PUBLIC__static/js/md5.js"></script>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form" method="post">
            <div class="layui-form-item">
                <label for="nickName" class="layui-form-label">
                    <span class="x-red">*</span>昵称/账号
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="nickName" name="nickName" value="{$info.nickName}" required="" lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>将会成为您唯一的登入名
                </div>
            </div>
            <div class="layui-form-item">
                <label for="name" class="layui-form-label">
                    <span class="x-red">*</span>姓名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="name" name="name" value="{$info.name}" required="" lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="phone" class="layui-form-label">
                    <span class="x-red">*</span>手机
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="phone" name="phone" value="{$info.phone}" required="" lay-verify="required|phone"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>性别
                </label>
                <div class="layui-input-block">
                    <input type="radio" name="sex" value="男" title="男" {if $info.sex=='男'}checked{/if} >
                    <input type="radio" name="sex" value="女" title="女" {if $info.sex=='女'}checked{/if} >
                </div>
            </div>
            <div class="layui-form-item">
                <label for="phone" class="layui-form-label">
                    <span class="x-red">*</span>年龄
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="age" name="age" value="{$info.age}" required="" lay-verify="required|number"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span class="x-red">*</span>预约项目</label>
                <div class="layui-input-inline">
                    <select name="yyitem" lay-verify="required">
                        <option value="暂时不定" {if $info.yyitem=='暂时不定'}selected{/if} >暂时不定</option>
                        <option value="思维启蒙班" {if $info.yyitem=='思维启蒙班'}selected{/if} >思维启蒙班</option>
                        <option value="少年创客班" {if $info.yyitem=='少年创客班'}selected{/if} >少年创客班</option>
                        <option value="青年造物班" {if $info.yyitem=='青年造物班'}selected{/if} >青年造物班</option>
                        <option value="奥赛助力班" {if $info.yyitem=='奥赛助力班'}selected{/if} >奥赛助力班</option>
                        <option value="特色数学班" {if $info.yyitem=='特色数学班'}selected{/if} >特色数学班</option>
                        <option value="成人筑梦班" {if $info.yyitem=='成人筑梦班'}selected{/if} >成人筑梦班</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="desc" class="layui-form-label">
                    <span class="x-red"></span>说明
                </label>
                <div class="layui-input-block">
                    <textarea name="desc" id="desc" placeholder="请输入内容" class="layui-textarea">{$info.desc}</textarea>
                </div>
            </div>
            <!--<div class="layui-form-item">
                <label for="L_pass" class="layui-form-label">
                    <span class="x-red">*</span>密码
                </label>
                <div class="layui-input-inline">
                    <input type="password" id="L_pass" name="pass" required="" lay-verify="pass"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    6到16个字符
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label">
                    <span class="x-red">*</span>确认密码
                </label>
                <div class="layui-input-inline">
                    <input type="password" id="L_repass" name="repass" required="" lay-verify="repass"
                           autocomplete="off" class="layui-input">
                </div>
            </div>-->
            <div class="layui-form-item">
                <label class="layui-form-label">
                </label>
                <button  class="layui-btn" lay-filter="add" lay-submit="">
                    增加
                </button>
            </div>
        </form>
    </div>
</div>
<script>layui.use(['form', 'layer'],
    function() {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;

        //自定义验证规则
        form.verify({
            nickName: function(value) {
                if (value.length < 2) {
                    return '昵称至少得2个字符啊';
                }
            },
            /*pass: [/(.+){6,12}$/, '密码必须6到12位'],
            repass: function(value) {
                if ($('#L_pass').val() != $('#L_repass').val()) {
                    return '两次密码不一致';
                }
            }*/
        });

        //监听提交
        form.on('submit(add)',
            function(data) {
                //console.log(data);
                var nickName = data.field.nickName;
                var name = data.field.name;
                var sex = data.field.sex;
                var age = data.field.age;
                var phone = data.field.phone;
                var yyitem = data.field.yyitem;
                var formData = {
                    'nickName' : nickName,
                    'name' : name,
                    'sex' : sex,
                    'age' : age,
                    'phone' : phone,
                    'yyitem' : yyitem,
                    'id' : '{$info.id}',
                    'desc' : data.field.desc
                };
                //发异步，把数据提交给php
                /*$.ajax({
                    //请求方式
                    type : "POST",
                    //请求的媒体类型
                    contentType: "application/json;charset=UTF-8",
                    //请求地址
                    url : "{:url('student/yy/adddo')}",
                    //数据，json字符串
                    data : JSON.stringify(formData),
                    //请求成功
                    success : function(res) {
                        console.log(res);
                        if(parseInt(res.statusCode)==200){
                            layer.msg(res.message, {
                                    icon: 6
                                },
                                function() {
                                    //关闭当前frame
                                    xadmin.close();
                                    // 可以对父窗口进行刷新
                                    xadmin.father_reload();
                                });
                        }else{
                            layer.msg(res.message);
                        }
                    },
                    //请求失败，包含具体的错误信息
                    error : function(e){
                        console.log(e.status);
                        console.log(e.responseText);
                    }
                });*/

                //发异步，把数据提交给php
                $.getJSON("{:url('student/yy/editdo')}",formData,function(res){
                    if(parseInt(res.statusCode)==200){
                        layer.msg(res.message, {
                                icon: 6
                            },
                            function() {
                                //关闭当前frame
                                xadmin.close();
                                // 可以对父窗口进行刷新
                                xadmin.father_reload();
                            });
                    }else{
                        layer.msg(res.message);
                    }

                });

                return false;
            });

    });

    function delAll (argument) {
        var ids = [];

        // 获取选中的id
        $('input.role').each(function(index, el) {
            if($(this).prop('checked')){
                ids.push($(this).val())
            }
        });

        return ids.toString();
    }
</script>

</body>

</html>
